package com.leon.workenginespace.event;

import org.springframework.context.ApplicationEvent;

/**
 * @description: 事件基类
 * @author: WT
 * @date: 2024/3/21 0:03
 * @Version 1.0
 **/
public class BaseEvent<T extends EventData> extends ApplicationEvent implements Comparable<BaseEvent> {

    private static final long serialVersionUID = 1L;

    private final T eventData;

    private final Integer priority;

    public BaseEvent(T eventData) {
        super(eventData);
        this.eventData = eventData;
        this.priority = EventPrioity.MIDDLE_PRIOITY.getPrioity();
    }

    public BaseEvent(T eventData, Integer prioity) {
        super(eventData);
        this.eventData = eventData;
        this.priority = prioity;
    }

    @Override
    public int compareTo(BaseEvent o) {
        return this.priority.compareTo(o.priority);
    }

    public Integer getPriority() {
        return priority;
    }
}